package com.qf.edu.dao.impl;

import com.qf.edu.dao.ImgPath;
import com.qf.edu.entity.Imgpath;
import com.qf.edu.entity.Users;
import com.qf.edu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:ImgPath接口实现类
 * @datatime: 2022/6/7 10:49
 */
public class ImgPathImpl implements ImgPath {
    QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());
    @Override
    public int setimgpath(String path,String name) {
        String sql = "UPDATE imgpath SET `path` = ? WHERE `usersName` = ?";
        try {
            int update = queryRunner.update(sql, new Object[]{path,name});
            return update;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Imgpath getpath(String name) {
        String sql = "SELECT * FROM imgpath WHERE `usersName` = ?";
        try {
            Imgpath query = queryRunner.query(sql, new BeanHandler<>(Imgpath.class), name);
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
